package com.dream.technology.components.engine;


import lombok.extern.slf4j.Slf4j;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

/**
 * 描述：
 *
 * @author chen_q_i@163.com
 * 2019/1/3 : 19:18.
 * @version : 1.0
 */
@Slf4j
public class JsEngineEVel {

   static final ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
   static final ScriptEngine nashorn = scriptEngineManager.getEngineByName("nashorn");

    public static Boolean getBoolean(String expression) {
        Boolean b = false;
        expression= expression.replaceAll("&+","&&");
        expression= expression.replaceAll("\\|+","||");
        try {
            b = (Boolean) nashorn.eval(expression);
        } catch (ScriptException e) {
            return b;
        }catch (ClassCastException e){
            return b;
        }
        return b;
    }


}
